import { createStore } from "vuex";

const store = createStore({
  state: {
    hasLogin: false,
    userInfo: {
      UID: "",
      TOKEN: "",
      type: "",
    },
  },
  mutations: {
    login(state, userInfo) {
      //登录状态为已登录
      state.hasLogin = true;
      state.userInfo = userInfo;
      // //储存用户数据到本地
      // uni.setStorage({
      //   key: "userInfo",
      //   data: user,
      // });
      console.debug("登陆成功");
      console.debug(state.hasLogin, state.userInfo);
    },
    // 退出登录
    logout(state, user) {
      //登录状态为未登录
      state.hasLogin = false;
      state.userInfo = {};
      // //删除本地储存
      // uni.removeSavedFile({
      // 	key: 'userInfo',
      // })
      console.debug("退出登录");
      console.debug(state.hasLogin, state.userInfo);
    },
    // updateUID(state, uid) {
    //   state.UID = uid;
    // },
    // updateTOKEN(state, token) {
    //   state.TOKEN = token;
    // },
    // 登录
  },
  actions: {
    // 定义actions，用于修改状态(异步)
  },
  getters: {
    getUID(state) {
      return state.userInfo.UID;
    },
    getTOKEN(state) {
      return state.userInfo.TOKEN;
    },
    getIsCustomer(state) {
      return state.userInfo.type === "customer";
    },
    getIsPE(state) {
      return state.userInfo.type === "pe";
    },
  },
  modules: {},
});

export default store;
